package com.ten.mall.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.ten.mall.mapper.CartMapper;
import com.ten.mall.service.CartService;
import com.ten.mall.vo.Cart;
import com.ten.mall.vo.CartExample;
import com.ten.mall.vo.CartExample.Criteria;
@Service
@Transactional
public class CartServiceImpl implements CartService {
	@Autowired
	private CartMapper cartMapper;
	@Override
	@Transactional(readOnly=true)
	public List<Cart> selectByPages(Integer start, Integer size, String name) {
		PageHelper.startPage(start, size);
		CartExample example =new CartExample();
		Criteria c =example.createCriteria();
		if(StringUtils.isNotBlank(name)){
			c.andGoodsTestEqualTo(name);
		}
		List<Cart> list =cartMapper.selectByExample(example);
		return list;
	}

	@Override
	public int insertCart(Cart record) {
		int i =cartMapper.insert(record);
		return i;
	}

	@Override
	public int updateCart(Cart record) {
		int i =cartMapper.updateByPrimaryKeySelective(record);
		return i;
	}

	@Override
	public int deleteCart(Integer id) {
		int i =cartMapper.deleteByPrimaryKey(id);
		return i;
	}

	@Override
	@Transactional(readOnly=true)
	public Cart selectById(Integer id) {
		Cart cart =cartMapper.selectByPrimaryKey(id);
		return cart;
	}
	
}
